#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>

/**
 *  (1)
 * sysconf获取在运行时获取系统的各种配置值
 *  _PC_PATH_MAX用于获取系统上文件路径的最大长度
 * 
 * (2)
 * int pathLength = readlink("/proc/self/exe", (char*)path.c_str(), length);
 * readlink 被用来获取当前进程可执行文件的实际路径
 * "/proc/self/exe": 这是 Linux 特殊的符号链接，指向当前进程的可执行文件
 * (char *)path.c_str(): 存储结果的缓冲区
 * length: 缓冲区的大小
 */
int main()
{
    int length = sysconf(_PC_PATH_MAX);
    printf("_PC_PATH_MAX = %d\n", length);

    std::string path;
    path.resize(length);
    int pathLength = readlink("/proc/self/exe", (char*)path.c_str(), length);
    printf("pathLength = %d\n", pathLength);
    printf("path = %s\n", path.c_str());
}